package com.itheima.api;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.PmsSkuStockMapper;
import com.itheima.pojo.db.PmsSkuStock;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsSkuStockApiImpl implements PmsSkuStockApi {
    @Autowired
    private PmsSkuStockMapper pmsSkuStockMapper;


    @Override
    public void insertList(List<PmsSkuStock> list, Long productId) {
        for (PmsSkuStock pmsSkuStock : list) {
            pmsSkuStock.setId(null);
            pmsSkuStock.setProductId(productId);
            pmsSkuStockMapper.insert(pmsSkuStock);
        }
    }

    @Override
    public void delete(Long id) {
        pmsSkuStockMapper.delete(new LambdaQueryWrapper<PmsSkuStock>().eq(PmsSkuStock::getProductId, id));
    }

    @Override
    public List<PmsSkuStock> selectByPid(Long id) {
        return pmsSkuStockMapper.selectList(new LambdaQueryWrapper<PmsSkuStock>().eq(PmsSkuStock::getProductId, id));
    }

    @Override
    public List<PmsSkuStock> selectList(Long pid, String keyword) {
        return pmsSkuStockMapper.selectList(new LambdaQueryWrapper<PmsSkuStock>().eq(PmsSkuStock::getProductId,pid).like(ObjectUtil.isNotEmpty(keyword),PmsSkuStock::getSkuCode,keyword));
    }
}
